package com.guigu.commons.handler;

import com.guigu.commons.utils.AuthCode;
import com.guigu.commons.utils.ResponseUtil;
import com.guigu.commons.utils.ResultResponseUtil;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @ClassName:AccessDeniedHandler
 * @Description:无权访问
 * @Author:longtao
 * @Date:2021/6/29
 * @Version:1.0
 */
public class AxiosAccessDeniedHandler implements AccessDeniedHandler {

    /**
     * 无权限访问的URL则会进入到此方法中
     * @param request
     * @param response
     * @param accessDeniedException
     * @throws IOException
     * @throws ServletException
     */
    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
        System.out.println("无权限");
         ResponseUtil.out(response,new ResultResponseUtil(false,"您未获得该操作的权限!", AuthCode.NO_PERMISSION_CODE));
    }
}
